package com.piedra.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo1 {
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class<?> clazz1 = null;
		clazz1 = Class.forName("com.piedra.reflect.Person");
		Person p = null;
		
		Constructor<?>[] cons = clazz1.getConstructors();
		
		for(Constructor con : cons){
			System.out.println(con.getName());
			p = (Person) con.newInstance("abc");
		}
		
		/*
		p = (Person) clazz1.newInstance();
		*/
		//p.setName("abc");
		
		System.out.println(p);
	}
}
	
class Person{
	private String name;
	
	public Person(String name){
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString(){
		return name;
	}
}